package org.zergle.scrapture.gui;

import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * 屏幕捕获工具
 * 
 * @author Johnson Lee
 *
 */
public class ScreenCapture {
	private static final long serialVersionUID = 7986803972219268236L;
	private static Toolkit toolkit = Toolkit.getDefaultToolkit();
	public static Dimension DIM_SCREEN = toolkit.getScreenSize();
	
	public ScreenCapture() {
		try {
			BufferedImage img = new Robot().createScreenCapture(new Rectangle(DIM_SCREEN));
			JFrame frame = new JFrame();
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			Canvas canvas = new Canvas(frame, img);
			canvas.setAction(CanvasAction.CUT);
			frame.setSize(DIM_SCREEN);
			frame.setResizable(false);
			frame.setTitle("Screen Capture");
			frame.setUndecorated(true);
			frame.add(canvas, BorderLayout.CENTER);
//			frame.setAlwaysOnTop(true);
			frame.setVisible(true);
		} catch (AWTException e) {
			JOptionPane.showMessageDialog(null, e.getMessage());
			System.exit(0);
		}
	}
	
	public static void main(String[] args) {
		new ScreenCapture();
	}
}